//引入的一个函数
const { expressjwt } = require("express-jwt")
//进行token认证
const jwtAuth = expressjwt({
    secret: "zheshimiyao", //加密的密钥
    algorithms: ["HS256"], //默认加密采用HS256
    credentialsRequired: true, //不管请求有没有携带，都需验证 （false:不验证）
}).unless({
    //白名单
    path: [
        "/users/login",
        "/users/register",
        "/users/updateUserInfo",
        /\/types\/.*/,
        /\/points\/.*/,
        /\/testeds\/.*/,
        /\/errors\/.*/,
        /\/exercises\/.*/,
        /\/collections\/.*/,
        /\/tests\/.*/,
        /\/exercises\/.*/,
        /\/file\/.*/
    ]
})

module.exports = jwtAuth